import java.util.*;
import java.io.*;
import java.sql.*;

public class BlobDownload 
{

/**
 * @param args
 */
	public static void main(String[] args) throws SQLException
	{
		DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
		
		Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@146.187.134.17:1542:oracle10g", "cscd494", "R3tral435");
		 // @machineName:port:SID,   userid,  password
		
		Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
		ResultSet rset = stmt.executeQuery("select * FROM APE_DOCUMENT");
		
		rset.absolute(2);
		String filename = rset.getString("FILE_NAME");
		try
		{
			Blob b = rset.getBlob(3);
			BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(new File(filename)));
			os.write(b.getBytes(1, (int)b.length()), 0, (int)b.length());
			os.flush();
			os.close();
		}
		catch(Exception e){}
		
		stmt.close();
	}
}
